#!/bin/bash
# c++11.sh
# This script will compile and run a C++11 program
# Usage: ./c++11.sh <filename.cpp>

# Check if a filename was provided
if [ $# -eq 0 ]; then
  echo "Usage: $0 <filename.cpp>"
  exit 1
fi

# Check if the file exists
if [ ! -f "$1" ]; then
  echo "File $1 does not exist."
  exit 1
fi

# Check if the file has a .cpp extension
if [[ "$1" != *.cpp ]]; then
  echo "File $1 is not a C++ file."
  exit 1
fi

# Compile the file with g++
g++ -std=c++11 $1 

# Check if the compilation was successful
if [ $? -ne 0 ]; then
  echo "Compilation failed."
  exit 1
fi

# Run the compiled program
./a.out

# Check if the program ran successfully
if [ $? -ne 0 ]; then
  echo "Program failed to run."
  exit 1
fi

# Clean up by removing the compiled program